<?php
class pro_perlengkapan_gedung_model extends MY_Model {
	function getApp()
	{
		$ls_sql	= "	SELECT	APP_ID value,
							APP_NAME display
					FROM	ADMIN_PRIMKOKAS.IT_APPLICATION
					ORDER BY APP_NAME";
					
		$result	= $this->db->query($ls_sql);
		if($result->num_rows() > 0){
			return $result->result_array();
		}else{
			return array();
		}
	}
	function GetJSON()
	{
		$ls_sql	= "	SELECT	*
					FROM	pro_barang 
					WHERE	jenis_kebutuhan LIKE 'Kebersihan Gedung'
					ORDER BY ".(post('sort')=='' ? 'id_perangkat' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		return json_encode( $this->paging($ls_sql) );
	}

	function Add($arr_data){

		$this->db->insert('pro_barang', $arr_data);
	}

	function Update($arr_data, $arr_rule){
		$a = $this->db->update('pro_barang', $arr_data, $arr_rule);
	}

	function GetSingle($as_id_perangkat){
		$result = $this->db->get_where('pro_barang', array('id_perangkat' => $as_id_perangkat));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_id_perangkat)
	{
		$result = $this->db->get_where('pro_barang', array('id_perangkat' => $as_id_perangkat));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule) {
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM ADMIN_PRIMKOKAS.PRO_BARANG WHERE id_perangkat = '".$arr_rule['id_perangkat']."'"))<=0)
			{
				return $this->error_delete.' [id: '.$arr_rule['id_perangkat']."]<br /> SELECT COUNT(1) FROM ADMIN_PRIMKOKAS.PRO_BARANG WHERE id_perangkat = '".$arr_rule['id_perangkat']."'";
			}else{
				$this->db->delete('ADMIN_PRIMKOKAS.PRO_BARANG', array('id_perangkat' => $arr_rule['id_perangkat']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}

	

}
?>